package com.bawei.mvp.http.factroy;


import com.bawei.mvp.http.product.DefProductImpl;
import com.bawei.mvp.http.product.IProduct;
import com.bawei.mvp.http.product.NetworkProductImpl;

public class HttpFactory implements IFactory {


    private NetworkProductImpl networkProduct;
    private DefProductImpl defProduct;


    @Override
    public IProduct getHttp(HttpType type) {
        switch (type) {
            default:
            case DEF:
                if (defProduct == null){
                    defProduct = new DefProductImpl();
                }
                return defProduct;
            case NETWORK:
                if (networkProduct == null){
                    networkProduct = new NetworkProductImpl();
                }
                return networkProduct;
        }
    }

    private volatile static HttpFactory httpFactory;

    public static HttpFactory getInstance() {
        if (httpFactory == null) {
            synchronized (HttpFactory.class) {
                if (httpFactory == null) {
                    httpFactory = new HttpFactory();
                }
            }
        }
        return httpFactory;
    }

    private HttpFactory() {
    }
}
